/*
    YmsgIRC - Program enabling YMSG chat clients to use IRC
    Copyright (C) 2011 Crash Daemonicus ( crashenator -at- gmail.com )

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
/**
@file sockets_cross.h
@brief ...
@details ...
@author crashenator (crashenator -at- gmail.com)
*/




#pragma once
#include <string>
using namespace std;
#ifdef _WIN32
	#include <WinSock2.h>
    #pragma comment(lib, "ws2_32.lib")// GCC suggest you use -lws2_32 (libws2_32.a), can't use a statement to link with it.
    #define XSADATA WSADATA
    #define XSAStartup(a,b) WSAStartup(a,b)
    #define XSACleanup() WSACleanup()
    #define XSAGetLastError() WSAGetLastError()
    
    #define XSAEWOULDBLOCK WSAEWOULDBLOCK
    #define XSAEAGAIN XSAEWOULDBLOCK
#else
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <netdb.h>
    
    typedef struct {
        int dummy;
    } XSADATA;
    typedef unsigned int u_int;
    typedef u_int SOCKET;
    #define INVALID_SOCKET (SOCKET)(~0)//will equal (int) -1
    #if !defined(EAGAIN) && defined(EWOULDBLOCK)
        #define EAGAIN EWOULDBLOCK
    #endif
    #if defined(EAGAIN) && !defined(EWOULDBLOCK)
        #define EWOULDBLOCK EAGAIN
    #endif
	#define XSAEWOULDBLOCK EWOULDBLOCK
    #define XSAEAGAIN XSAEWOULDBLOCK
    
    #define closesocket(s) close(s);
    #define XSAStartup(a,b) 0
    #define XSACleanup() 0
    #define XSAGetLastError() errno
#endif
int XSABlock(SOCKET& s,bool block=true);

bool XSASinFromName(const string& name, sockaddr_in& sin_out);

